from selenium.webdriver.common.by import By

from web_pratice.base_page import BasePage
from web_pratice.contact_page import ContactPage


class AddmemberPage(BasePage):

    _username_locator = (By.CSS_SELECTOR,"#username")
    _acctid_locator = (By.CSS_SELECTOR,"#memberAdd_acctid")
    _phone_locarot = (By.CSS_SELECTOR,"#memberAdd_phone")
    _save_locator = (By.CSS_SELECTOR,"form.js_member_editor_form>div:nth-child(3)>a.js_btn_save")

    def add_member(self,name,account_name,phone_number):
        '''

        :param name: 姓名
        :param account_name: 账号
        :param phone_number: 手机号码
        :return: 成员列表
        '''
        # 输入姓名
        self.find(self._username_locator).send_keys(name)
        # 输入账号
        self.find(self._acctid_locator).send_keys(account_name)
        # 输入手机号码
        self.find(self._phone_locarot).send_keys(phone_number)
        # 点击保存
        self.find(self._save_locator).click()
        # 跳转到成员列表
        return ContactPage(self.driver)

    def add_member_fail(self,name,account_name=None,phone_number=None):
        # 输入姓名
        self.find(self._username_locator).send_keys(name)
        # 输入账号
        self.find(self._acctid_locator).send_keys(account_name)
        # 输入手机号码
        self.find(self._phone_locarot).send_keys(phone_number)
        # 点击保存
        self.find(self._save_locator).click()
        remand_list = []
        # 请填写帐号
        # if account_name == '':
        #     ele = self.find(By.CSS_SELECTOR,".member_edit_item_Account>div.ww_inputWithTips_WithErr>div")
        #     remand_list.append(ele.text)
        # 手机和邮箱不能同时为空
        # elif phone_number == '':
        #     ele = self.find(By.CSS_SELECTOR,".member_edit_formWrap>div:nth-child(2)>div:nth-child(1) div.ww_inputWithTips_tips")
        #     remand_list.append(ele.text)
        # 两个校验都存在
        if account_name == '' and phone_number == '':
            ele1 = self.find(By.CSS_SELECTOR, ".member_edit_item_Account>div.ww_inputWithTips_WithErr>div").text
            ele2 = self.find(By.CSS_SELECTOR,\
                            ".member_edit_formWrap>div:nth-child(2)>div:nth-child(1) div.ww_inputWithTips_tips").text
            ele = [ele1,ele2]
            remand_list.extend(ele)
        return remand_list